package com.tourism.website.articledisplay.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tourism.website.articledisplay.entity.ArticleImg;
import com.tourism.website.articledisplay.mapper.ArticleImgMapper;
import com.tourism.website.articledisplay.service.IArticleImgService;
import com.tourismwebsite.articledisplay.dto.ArticleImgDTO;
import org.mapstruct.Mapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lyc
 * @since 2024-06-11
 */
@Mapper(componentModel="spring")
interface MsArticleImgMapper{
    ArticleImgDTO ArticleImgToArticleImgDTO(ArticleImg articleImg);
}
@Service
public class ArticleImgServiceImpl extends ServiceImpl<ArticleImgMapper, ArticleImg> implements IArticleImgService {
    @Resource
    MsArticleImgMapper msArticleImgMapper;
    @Override
    public List<ArticleImgDTO> queryArticleImg(Integer articleId) {
        LambdaQueryWrapper<ArticleImg> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ArticleImg::getArticleId,articleId);
        wrapper.select(ArticleImg::getArticleSort,ArticleImg::getImg);
        List<ArticleImg> articleImgs = baseMapper.selectList(wrapper);
        List<ArticleImgDTO> articleImgDTOS = articleImgs.stream()
                .map(articleImg -> msArticleImgMapper.ArticleImgToArticleImgDTO(articleImg))
                .collect(Collectors.toList());
        return articleImgDTOS;
    }
}
